package bawei.com.adapter;


import android.content.Context;

import android.support.v7.widget.RecyclerView;



import android.view.LayoutInflater;

import android.view.View;
import android.view.ViewGroup;


import android.widget.ImageView;
import android.widget.TextView;



import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;

import java.util.List;



import bawei.com.bilibili.R;
import bawei.com.model.bean.TopicBean;

/**
 * 类描述:
 * 作者：cwm
 * 时间:2017/3/19 18:31
 * 邮箱:18310832074@163.com
 */

public
class
TopicAdapter extends RecyclerView.Adapter{

    private Context context;
    private List<TopicBean.ListBean> listBean;


    public TopicAdapter(Context context, List<TopicBean.ListBean> listBean) {
        this.context = context;
        this.listBean = listBean;
    }

    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new TopicViewHolder(LayoutInflater.from(context).inflate(R.layout.item_topic_center,parent,false));
    }

    @Override
    public void onBindViewHolder(RecyclerView.ViewHolder holder, final int position) {

        if (holder instanceof TopicViewHolder) {
            TopicViewHolder itemViewHolder = (TopicViewHolder) holder;
            Glide.with(context)
                    .load(listBean.get(position).getCover())
                    .centerCrop()
                    .diskCacheStrategy(DiskCacheStrategy.ALL)
                    .placeholder(R.drawable.bili_default_image_tv)
                    .dontAnimate()
                    .into(itemViewHolder.mImage);

            itemViewHolder.mTitle.setText(listBean.get(position).getTitle());
        itemViewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onclientLiker.OnclientLikerRecy(position);
            }
        });
        }

    }

    @Override
    public int getItemCount() {

        return listBean.size();
    }

    class TopicViewHolder extends RecyclerView.ViewHolder{
        ImageView mImage;

        TextView mTitle;
        public TopicViewHolder(View itemView) {
            super(itemView);

            mImage= (ImageView) itemView.findViewById(R.id.item_image);
            mTitle= (TextView) itemView.findViewById(R.id.item_title);
        }
    }
    private OnclientLiker onclientLiker;

    public void setOnclientLiker(OnclientLiker OnclientLiker){

        this.onclientLiker=OnclientLiker;
    }

    public interface OnclientLiker{

        void OnclientLikerRecy(int p);

    }
}
